package simpleGui;

import java.util.ArrayList;

import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;

public class Gui {
	final static int DARK=0;
	final static int BRIGHT=1;
	public GuiStyle style;
	public  PApplet parent;
	public  PFont font;
	public int fontsize=10;
	public boolean visible=true;
	ArrayList<GuiComponent> children = new ArrayList<GuiComponent>();

	
	public void initStyle(int styleTheme){
		if (styleTheme==DARK){
			style= new GuiStyle();
			style.fillColor=parent.color(0);
			style.fillColorActivated=parent.color(255,0,0);
			style.strokeColor=parent.color(255);
			style.fillColorOver=parent.color(0);
			style.textColor=parent.color(255);
			style.strokeWeight=2;
		}
	}
	
	public Gui(PApplet parent, PFont font) {
		this.parent = parent;
		this.font = font;
		initStyle(DARK);
	}
	public Gui(PApplet parent) {
		this.parent = parent;
		initStyle(DARK);
	}
	public GuiClickButton addClickButton(int x, int y, int w, int h) {
		GuiClickButton button = new GuiClickButton(this, x, y, w, h);
		//children.add(button);
		return button;
	}
	public GuiComponent addComponent(int x, int y, int w, int h) {
		GuiComponent comp = new GuiComponent(this, x, y, w, h);
		//children.add(button);
		return comp;
	}
	public void addChildDisplay(GuiComponent comp){
		children.add(comp);
	}
	public GuiCheckButton addGuiButton(int x, int y, int w, int h, boolean state) {
		GuiCheckButton button = new GuiCheckButton(this, x, y, w, h, state);
		//children.add(button);
		return button;
	}

	public GuiLabel addGuiLabel(int x, int y,  String text) {
		GuiLabel label = new GuiLabel(this, x, y, text);
		//children.add(label);
		return label;
	}

	public GuiSlider addGuiSlider(int x, int y, int width, int height) {
		GuiSlider slider = new GuiSlider(this, x, y, width, height);
		//children.add(slider);
		return slider;
	}

	public GuiSpinnerGroup addGuiSpinnerGroup(int x, int y,float value,float min,float max, int nDigits,int comma) {
		GuiSpinnerGroup spinner = new GuiSpinnerGroup(this, x,  y, value, min, max,  nDigits, comma);
		//children.add(spinner);
		return spinner;
	}
	
	public GuiSpinnerGroup addGuiSpinnerGroup(int x, int y, int value, int min,
			int max) {
		GuiSpinnerGroup spinner = new GuiSpinnerGroup(this, x, y, value, min,
				max);
		//children.add(spinner);
		return spinner;
	}
	public boolean contains(int mX,int mY){
		for (int i=0;i<children.size();i++){
			GuiComponent gc=children.get(i);
			if (gc.contains(mX, mY))return true;
		}
		return false;
	}
	public void display(PGraphics g) {
		if (visible){
			g.strokeWeight(getStrokeWeight());
		for (int i = 0; i < children.size(); i++) {
			children.get(i).display(g);
		}
		}
	}
	public boolean isVisible() {
		return visible;
	}
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	public boolean equals(Object obj) {
		return style.equals(obj);
	}
	public int getStrokeColor() {
		return style.getStrokeColor();
	}
	public int getFillColor() {
		return style.getFillColor();
	}
	public int getFillColorActivated() {
		return style.getFillColorActivated();
	}
	public int getFillColorOver() {
		return style.getFillColorOver();
	}
	public int getTextColor() {
		return style.getTextColor();
	}

	public int getPadding() {
		return style.getPadding();
	}

	public int getStrokeWeight() {
		return style.getStrokeWeight();
	}
}
